const Koa = require('koa')
const app = new Koa()
const KoaRouter = require('koa-router');
const router = new KoaRouter();
// Node 接口限流
const RateLimit = require('koa2-ratelimit').RateLimit;


const getUserLimiter = RateLimit.middleware({
  interval: 60*1000, // 1 minutes
  max: 10,
  prefixKey: 'get/test', 
  message:'请求已经超过10次了,请一分钟后重试！',
  headers:true
});

router.get(
  '/test',
  getUserLimiter,
  (ctx)=>{
    ctx.body="test"
  }
)

app.use(router.middleware())


app.listen(4000,()=>{
  console.log('应用启动成功！请监听4000端口！')
})